home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / RelViewPos.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.4 KB  |  178 lines

  1. package symantec.itools.db.pro;
  2.  
  3. import java.io.EOFException;
  4. import java.util.Vector;
  5. import symantec.itools.db.net.BinaryInputStream;
  6. import symantec.itools.db.net.BinaryOutputStream;
  7. import symantec.itools.db.net.NetData;
  8. import symantec.itools.db.net.NetRecord;
  9. import symantec.itools.db.net.Param;
  10. import symantec.itools.db.net.RemoteObject;
  11. import symjava.sql.SQLException;
  12.  
  13. class RelViewPos {
  14.    Vector _relInfo;
  15.    RelViewInfo _curInfo;
  16.    int _offset;
  17.    MultiView _mv;
  18.    RemoteObject _mvRemObj;
  19.  
  20.    RelViewPos(MultiView mv) {
  21.       this._mv = mv;
  22.       this._relInfo = new Vector();
  23.       this._curInfo = null;
  24.       this._offset = 0;
  25.    }
  26.  
  27.    MultiView getMultiView() {
  28.       return this._mv;
  29.    }
  30.  
  31.    RemoteObject getMVRemObj() {
  32.       return this._mvRemObj;
  33.    }
  34.  
  35.    RelViewPos cloneAtCurrentPos() {
  36.       RelViewPos pos = new RelViewPos(this.getMultiView());
  37.  
  38.       for(int i = this._offset; i > 0; --i) {
  39.          pos.addParentInfo((RelViewInfo)this._relInfo.elementAt(i - 1));
  40.       }
  41.  
  42.       pos.setMVRemObj(this._mvRemObj);
  43.       return pos;
  44.    }
  45.  
  46.    RelViewPos next() {
  47.       if (!this.over()) {
  48.          this._curInfo = (RelViewInfo)this._relInfo.elementAt(this._offset++);
  49.       } else {
  50.          this._curInfo = null;
  51.       }
  52.  
  53.       return this;
  54.    }
  55.  
  56.    RelViewPos reset() {
  57.       this._offset = 0;
  58.       this._curInfo = null;
  59.       if (this._relInfo.size() > 0) {
  60.          this._curInfo = (RelViewInfo)this._relInfo.elementAt(this._offset++);
  61.       }
  62.  
  63.       return this;
  64.    }
  65.  
  66.    boolean over() {
  67.       if (this._curInfo == null) {
  68.          return true;
  69.       } else {
  70.          return this._curInfo.getRecNum() == 0;
  71.       }
  72.    }
  73.  
  74.    int getRowsToRequest() {
  75.       if (this._relInfo.size() > 0) {
  76.          RelViewInfo info = (RelViewInfo)this._relInfo.elementAt(this._relInfo.size() - 1);
  77.          return info.getNumRowsToRequest();
  78.       } else {
  79.          return 1;
  80.       }
  81.    }
  82.  
  83.    int getID() {
  84.       return this._curInfo.getID();
  85.    }
  86.  
  87.    int getRecNum() {
  88.       return this._curInfo.getRecNum();
  89.    }
  90.  
  91.    int getProxyID() {
  92.       return this._curInfo.getProxyID();
  93.    }
  94.  
  95.    void addParentInfo(RelViewInfo info) {
  96.       this._relInfo.insertElementAt(info, 0);
  97.    }
  98.  
  99.    void setMVRemObj(RemoteObject obj) {
  100.       this._mvRemObj = obj;
  101.    }
  102.  
  103.    private void addPosInfoToParams(Vector params) {
  104.       params.addElement(new Param(0, this._relInfo.size()));
  105.  
  106.       for(int i = 0; i < this._relInfo.size(); ++i) {
  107.          RelViewInfo info = (RelViewInfo)this._relInfo.elementAt(i);
  108.          params.addElement(new Param(0, info.getProxyID(), true));
  109.          params.addElement(new Param(0, info.getRecNum()));
  110.       }
  111.  
  112.    }
  113.  
  114.    int getRemoteStreamID(int recID, int colIndex) throws SQLException {
  115.       Vector params = new Vector();
  116.       params.addElement(new Param(0, recID));
  117.       params.addElement(new Param(0, colIndex));
  118.       this.addPosInfoToParams(params);
  119.       Vector results = this._mvRemObj.invokeMethod(9, params);
  120.       NetData d = (NetData)results.elementAt(0);
  121.  
  122.       try {
  123.          return d.getInt();
  124.       } catch (EOFException e) {
  125.          throw new SQLException(((Throwable)e).getMessage());
  126.       }
  127.    }
  128.  
  129.    BinaryInputStream getRemoteInputStream(int recID, int colIndex) throws SQLException {
  130.       int id = this.getRemoteStreamID(recID, colIndex);
  131.       return new BinaryInputStream(id, this._mvRemObj.getSession());
  132.    }
  133.  
  134.    BinaryOutputStream getRemoteOutputStream(int recID, int colIndex) throws SQLException {
  135.       int id = this.getRemoteStreamID(recID, colIndex);
  136.       return new BinaryOutputStream(id, this._mvRemObj.getSession());
  137.    }
  138.  
  139.    NetRecord getNewServerRecord() throws SQLException {
  140.       Vector params = new Vector();
  141.       this.addPosInfoToParams(params);
  142.       Vector results = this._mvRemObj.invokeMethod(7, params);
  143.       return (NetRecord)results.elementAt(0);
  144.    }
  145.  
  146.    void deleteServerRecord(NetRecord rec, int recnum) throws SQLException {
  147.       Vector params = new Vector();
  148.       params.addElement(new Param(0, recnum));
  149.       this.addPosInfoToParams(params);
  150.       this._mvRemObj.invokeMethod(6, params);
  151.       rec.setState((byte)103);
  152.    }
  153.  
  154.    void undoServerRecord(NetRecord rec, int recnum) throws SQLException {
  155.       Vector params = new Vector();
  156.       params.addElement(new Param(0, recnum));
  157.       this.addPosInfoToParams(params);
  158.       Vector results = this._mvRemObj.invokeMethod(5, params);
  159.       NetRecord newrec = (NetRecord)results.elementAt(0);
  160.       rec.copy(newrec);
  161.    }
  162.  
  163.    void notifyServerOfDataChange(NetRecord rec) throws SQLException {
  164.       Vector params = new Vector();
  165.       params.addElement(rec);
  166.       this.addPosInfoToParams(params);
  167.       this._mvRemObj.invokeMethod(1, params);
  168.    }
  169.  
  170.    Vector fetchRecords(int startRec, int numRecs) throws SQLException {
  171.       Vector params = new Vector();
  172.       params.addElement(new Param(0, startRec));
  173.       params.addElement(new Param(0, numRecs));
  174.       this.addPosInfoToParams(params);
  175.       return this._mvRemObj.invokeMethod(0, params);
  176.    }
  177. }
  178.